<template>
    <a-card :bordered="false">
        <!-- model弹窗 -->
        <a-modal v-model="visible" title="Modal" ok-text="确认" cancel-text="取消" @ok="printpage ()"
            :width="900">
            <div style="width:100%;height: 100%;background-color: rgb(255, 255, 255);"
                class="printId">

                <div class="printId" id="printId">
                    <div>
                        <div style="text-align: center;">
                            <h2></h2>
                        </div>
                        <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns1"
                            :dataSource="this.zaiku" class="j-table-force-nowrap">

                        </a-table>
                    </div>
                </div>
            </div>
        </a-modal>
        <!-- model第二个弹窗 -->
        <a-modal v-model="visible1" title="Modal" ok-text="确认" cancel-text="取消"
            @ok="tongbu(shijizhongliang)" :width="900">
            请输入实际重量: <a-input v-model="shijizhongliang" placeholder="请输入实际重量"
                :value="shijizhongliang" />
        </a-modal>

        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="货物名称">
              <j-input placeholder="货物名称" v-model="queryParam.huaxuepinmingcheng"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="盘点人">
              <j-input placeholder="请输入盘点人" v-model="queryParam.pandianren"></j-input>
            </a-form-item>
          </a-col>
          
 
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>

           
            </span>
          </a-col>
        </a-row>
        </a-row>
      </a-form>
    </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
            <a-button type="primary" icon="download" @click="handleExportXls('盘点详情')">导出</a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"
                :action="importExcelUrl" @change="handleImportExcel">
                <a-button type="primary" idayinyulancon="import">导入</a-button>
            </a-upload>

            <!-- 高级查询区域 -->
            <j-super-query :fieldList="superFieldList" ref="superQueryModal"
                @handleSuperQuery="handleSuperQuery"></j-super-query>
            <a-dropdown v-if="selectedRowKeys.length > 0">
                <a-menu slot="overlay">
                    <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>

            </a-dropdown>

            请选择要盘点货物名称:
            <a-select v-decorator="['huaxuepinmingcheng']" @change="dayinyulan"
                style="width: 300px;" placeholder="请选择货物名称">
                <a-select-option v-for="item in this.huaxuepinmingList" :value="item" :key="item">
                    {{ item }}
                </a-select-option>
            </a-select>

            请选择计划名称:
            <a-select v-decorator="['jihuamingcheng']" @change="getByjihua" style="width: 300px;"
                placeholder="请选择计划名称">
                <a-select-option v-for="item in this.jihuamingList" :value="item" :key="item">
                    {{ item }}
                </a-select-option>
            </a-select>
        </div>
        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
                    style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns"
                :dataSource="dataSource" class="j-table-force-nowrap">

                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="getImgView(text)" height="25px" alt=""
                        style="max-width:80px;font-size: 12px;font-style: italic;" />
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button v-else :ghost="true" type="primary" icon="download" size="small"
                        @click="downloadFile(text)">
                        下载
                    </a-button>
                </template>

                <span slot="action" slot-scope="text, record">
                    <!-- <a @click="handleEdit(record)">编辑</a> -->
                    <a @click="handleDetail(record)">详情</a>
                    <a-divider type="vertical" />
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                        <a-menu slot="overlay">
                            <a-menu-item>
                                <!-- <a @click="handleDetail(record)">详情</a> -->
                            </a-menu-item>
                            <a-menu-item>
                                <a @click="tongbu(record)">保存记录</a>
                            </a-menu-item>
                            <!-- <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item> -->
                        </a-menu>
                    </a-dropdown>
                </span>

            </a-table>
        </div>

        <yzd-pandianxiangqing-modal ref="modalForm" @ok="modalFormOk"></yzd-pandianxiangqing-modal>
    </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import YzdPandianxiangqingModal from './modules/YzdPandianxiangqingModal'
import { getAction, postAction } from '../../api/manage'
import { get } from 'lodash'

export default {
    name: 'YzdPandianxiangqingList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
        YzdPandianxiangqingModal
    },
    data() {
        return {
            shijizhongliang: '',
            visible1: false,
            visible: false,
            description: '盘点详情管理页面',
            columns1: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '仓库名称',
                    align: "center",
                    dataIndex: 'cangkumingcheng'
                },
             /*   {
                    title: '单瓶批次号',
                    align: "center",
                    dataIndex: 'picihao'
                },*/
                {
                    title: '货物名称',
                    align: "center",
                    dataIndex: 'huaxuepinmingcheng'
                },
                {
                    title: '数量',
                    align: "center",
                    dataIndex: 'zhongliang'
                },
                /*{
                    title: '货架位置',
                    align: "center",
                    dataIndex: 'huojiaweizhi'
                },*/
                // {
                //   title:'二维码',
                //   align:"center",
                //   dataIndex: 'erweima',
                //   scopedSlots: { customRender: 'imgSlot' }
                // },

            ],



            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '计划名称',
                    align: "center",
                    dataIndex: 'jihuamingcheng'
                },
                {
                    title: '仓库名称',
                    align: "center",
                    dataIndex: 'cangkumingcheng'
                },
                {
                    title: '货物名称',
                    align: "center",
                    dataIndex: 'huaxuepinmingcheng'
                },
                {
                    title: '重量',
                    align: "center",
                    dataIndex: 'picihao'
                },

                // {
                //   title:'实际重量(克)',
                //   align:"center",
                //   dataIndex: 'shijizhongliang'
                // },
                // {
                //   title:'理论重量(克)',
                //   align:"center",
                //   dataIndex: 'lilunzhongliang'
                // },
                // {
                //   title:'差异重量(克)',
                //   align:"center",
                //   dataIndex: 'chayizhongliang'
                // },
                {
                    title: '盘点人',
                    align: "center",
                    dataIndex: 'pandianren'
                },
                // {
                //   title:'原因',
                //   align:"center",
                //   dataIndex: 'yuanyin'
                // },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: "center",
                    fixed: "right",
                    width: 147,
                    scopedSlots: { customRender: 'action' }
                }
            ],
            url: {
                queryByJihua: "/yzd_pandianmingxi/yzdPandianxiangqing/queryByJihua",
                getjihua: "/yzd_pandianmingxi/yzdPandianxiangqing/getjihua",
                tongbu: "/yzd_pandianmingxi/yzdPandianxiangqing/tongbu",
                zaikulist: "/yzd_zaikuguanli/zaikumingxi/getByHuaxuepinmingcheng",
                huaxuepinmingcheng: "/yzd_jichuxinxi/yzdWeixianfeiwuxinxi/list",
                list: "/yzd_pandianmingxi/yzdPandianxiangqing/list",
                delete: "/yzd_pandianmingxi/yzdPandianxiangqing/delete",
                deleteBatch: "/yzd_pandianmingxi/yzdPandianxiangqing/deleteBatch",
                exportXlsUrl: "/yzd_pandianmingxi/yzdPandianxiangqing/exportXls",
                importExcelUrl: "yzd_pandianmingxi/yzdPandianxiangqing/importExcel",

            },
            jihuamingList: [],
            dictOptions: {},
            superFieldList: [],
            huaxuepinmingList: [],
            zaiku: [],
            pandian: {},
        }
    },
    created() {
        this.getSuperFieldList();
        this.gethuaxuepinmingcheng();
        this.getjihuaming();
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        },
    },
    methods: {
        getByjihua(arr) {
            if (arr == "全部") {
                arr = ''
            }
            var re = {
                "jihuamingcheng": arr
            };
            getAction(this.url.queryByJihua, re).then(res => {
                // console.log(res);
                this.dataSource = res.result
            })
        },

        getjihuaming() {
            getAction(this.url.getjihua).then(res => {
                console.log("111111111调用方法");
                this.jihuamingList.push("全部")
                res.result.forEach(element => {
                    console.log(element.jihuamingcheng);
                    this.jihuamingList.push(element.jihuamingcheng)
                })
            })
        },

        tongbu(arr) {
            postAction(this.url.tongbu, arr).then(res => {
            })

        },
        openmodel(arr) {
            this.visible1 = true
            this.pandian = arr
        },

        printpage() {
            // 这里我们是对局部打印做的演示
            // 首先获取局部html，也就是打印的区域
            const printHTML = document.querySelector('#printId').innerHTML;
            // 将打印的区域赋值，进行打印
            window.document.body.innerHTML = printHTML;
            window.print(); // 调用window打印方法
            window.location.reload(); // 打印完成后重新加载页面
        },

        dayinyulan(huaxuepinmingcheng) {
            if (huaxuepinmingcheng == "全部") {
                huaxuepinmingcheng = ''
            }
            var re = {
                huaxuepinmingcheng: huaxuepinmingcheng
            }
            getAction(this.url.zaikulist, re).then(res => {
                this.zaiku = res.result
                this.visible = true
            })


        },



        gethuaxuepinmingcheng() {
            getAction(this.url.huaxuepinmingcheng).then(res => {
                this.huaxuepinmingList.push("全部")
                res.result.records.forEach(element => {
                    this.huaxuepinmingList.push(element.huaxuepinmingcheng)
                })
            })
        },


        initDictConfig() {
        },
        getSuperFieldList() {
            let fieldList = [];
            fieldList.push({ type: 'string', value: 'cangkumingcheng', text: '仓库名称', dictCode: '' })
            fieldList.push({ type: 'string', value: 'huaxuepinmingcheng', text: '货物名称', dictCode: '' })
            fieldList.push({ type: 'string', value: 'picihao', text: '批次号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'shijizhongliang', text: '实际重量', dictCode: '' })
            fieldList.push({ type: 'string', value: 'lilunzhongliang', text: '理论重量', dictCode: '' })
            fieldList.push({ type: 'string', value: 'chayizhongliang', text: '差异重量', dictCode: '' })
            fieldList.push({ type: 'string', value: 'yuanyin', text: '原因', dictCode: '' })
            fieldList.push({ type: 'string', value: 'pandianren', text: '盘点人', dictCode: '' })
            fieldList.push({ type: 'string', value: 'jihuamingcheng', text: '计划名称', dictCode: '' })
            this.superFieldList = fieldList
        }
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>